package com.xuecheng.orders.feignclient;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author itcast
 */
@Slf4j
@Component
public class AuthServiceClientFallbackFactory implements FallbackFactory<AuthServiceClient> {
    @Override
    public AuthServiceClient create(Throwable throwable) {
        return new AuthServiceClient() {
            @Override
            public String getName(String id) {
                log.error("查询用户姓名发生熔断，用户id：{}，异常信息：{}", id, throwable.toString(), throwable);
                return null;
            }

            @Override
            public Map<String, String> listNameByIds(List<String> ids) {
                log.error("批量查询用户姓名发生熔断，异常信息：{}", throwable.toString(), throwable);
                return new HashMap<>();
            }
        };
    }
}
